package tgc.rj.garbage;

import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.litepal.LitePal;

import tgc.rj.garbage.custom.ToastUtils;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText editText1;
    private EditText editText2;
    private TextView btn1;
    private TextView btn2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        editText1 = findViewById(R.id.editText1);
        editText2 = findViewById(R.id.editText2);
        btn1 = findViewById(R.id.btn1);
        btn1.setOnClickListener(this);
        btn2 = findViewById(R.id.btn2);
        btn2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn1:
                intent = new Intent(this, CommodityActivity.class);
                startActivity(intent);
//                String username = editText1.getText().toString();
//                String password = editText2.getText().toString();
//                String sql = "select * from admin where username= " + "'"+ username +"'" +" and password = " +"'" +password+"'";
//                Cursor cursor = LitePal.findBySQL(sql);
//                //判断是否查询到该管理员
//                if(cursor.getCount() != 0){
//                    Intent intent = new Intent(this, CommodityActivity.class);
//                    startActivity(intent);
//                    ToastUtils.toastUtils(this,"登陆成功");
//                }else{
//                    Toast.makeText(this,"用户名或密码错误", Toast.LENGTH_SHORT).show();
//                }
                break;

            case R.id.btn2:
                intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                finish();
                break;

            default:
                break;
        }
    }
}
